# -*- coding:utf-8 -*-
# @File       :   login_saas.py
# @Author     :   LINING
# @Time       :   2024/7/24 15:19
# @Description : saas登录
from Handle.handle_js import get_session_storage
from TestCase.Pages.login.login_saas import LoginSaas as login_saas
from Handle.handle_yaml import domain_saas, account_saas
from Core.waitOpt import Wait
from Core.pageOpt import Page


class LoginSaas:
    def __init__(self, page):
        self.page = page
        self.login_saas = login_saas(self.page)
        self.page_ = Page(self.page)

    # 输入用户名
    def fill_user_name(self, username):
        self.login_saas.fill_user_name(username)

    # 输入密码
    def fill_password(self, pwd):
        self.login_saas.fill_password(pwd)

    # 点击登录按钮
    def click_login(self):
        self.login_saas.click_login()

    # 获取登录成功
    def login_success(self):
        return self.login_saas.login_success()

    # 登录成功元素可见
    def login_success_visible(self):
        return self.login_saas.login_success()

    # 登录功能封装
    def login_saas_success(self):
        self.page_.page_goto(domain_saas)
        self.fill_user_name(account_saas[0])
        self.fill_password(account_saas[1])
        self.click_login()
        self.login_saas.login_success_wait()
        # 要等登录成功接口返回用户id
        Wait(self.page).wait_time(1)
        token = get_session_storage(self.page)
        return token

